package com.zqh.generator.file;



import cn.hutool.core.io.FileUtil;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 核心生成器
 */
public class FileGenerator {

    /**
     * 生成
     *
     * @param model 数据模型
     * @throws TemplateException
     * @throws IOException
     */
    public static void doGenerate(Object model) throws TemplateException, IOException {
//        String inputRootPath = "/Users/zqh/Documents/project/zqh-generator/zqh-generator-demo-projects/acm-template";
        String inputRootPath = ".source/acm-template";
        String outputRootPath = "/Users/zqh/Documents/project/zqh-generator/zqh-generator-maker/generated";

        String inputPath;
        String outputPath;

        inputPath = new File(inputRootPath, "src/com/zqh/acm/MainTemplate.java.ftl").getAbsolutePath();
        outputPath = new File(outputRootPath, "src/com/zqh/acm/MainTemplate.java").getAbsolutePath();
        DynamicFileGenerator.doGenerate(inputPath, outputPath, model);

        inputPath = new File(inputRootPath, ".gitignore").getAbsolutePath();
        outputPath = new File(outputRootPath, ".gitignore").getAbsolutePath();
        if(!FileUtil.exist(inputPath)){
            FileUtil.touch(inputPath);
            System.out.println(".gitignore");
        }
        StaticFileGenerator.copyFilesByHutool(inputPath, outputPath);

        inputPath = new File(inputRootPath, "README.md").getAbsolutePath();
        outputPath = new File(outputRootPath, "README.md").getAbsolutePath();
        if(!FileUtil.exist(inputPath)){
            FileUtil.touch(inputPath);
            System.out.println("README.md");
        }
        StaticFileGenerator.copyFilesByHutool(inputPath, outputPath);
    }

//
//    public static void main(String[] args) throws TemplateException, IOException {
//        DataModel dataModel = new DataModel();
//        dataModel.setAuthor("zqhXX");
//        dataModel.setLoop(false);
//        dataModel.setOutputText("求和结果：");
//        doGenerate(dataModel);
//
//    }
}


